<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   家居商家优惠活动控制器($小牛New $2014.07.28)*/

!defined('Q_PATH') && exit;

class JiajueventController extends AController{

	public function init__(){
		$this->_arrNotMethod=array(
			'save_previewstatus',
			'save_preview',
			'view_preview',
			'foreverdelete_deep',
			'input_change_unique',
			'forbid',
			'resume',
			'clear_recycle',
			'save_sort'
		);
		
		parent::init__();
	}
	
	public function filter_(&$arrMap){
		$arrMap['A.jiajuevent_title']=array('like',"%".Q::G('jiajuevent_title')."%");
		$arrMap['A.jiajuevent_description']=array('like',"%".Q::G('jiajuevent_description')."%");
		$arrMap['A.jiajuevent_viewnum']=array('egt',intval(Q::G('jiajuevent_viewnum')));
		$arrMap['A.jiajucompany_id']=$GLOBALS['_company_']['jiajucompany_id'];
		
		// 添加时间
		$this->getTime_('A.create_dateline',$arrMap);
	}

	public function bEdit_(){
		$nId=intval(Q::G('id','G'));
		// 活动内容
		$sContent=JiajueventcontentModel::F('jiajuevent_id=?',$nId)->getColumn('jiajuevent_content');
		$this->assign('sContent',$sContent);
	}

	protected function AEditObject_($oModel){
		if(in_array($oModel->jiajuevent_status,array(9,3)) || $oModel->jiajucompany_id!=$GLOBALS['_company_']['jiajucompany_id']){
			$this->E('你没有权限访问。');
		}
	}

	public function insert($sModel=null,$nId=null){
		$oJiajuevent=new JiajueventModel();
		$oJiajuevent->saveData($GLOBALS['_company_']);
		if($oJiajuevent->isError()){
			$this->E($oJiajuevent->getErrorMessage());
		}

		$this->A($oJiajuevent->toArray(),'活动添加成功',1);
	}

	public function update($sModel=null,$nId=null){
		$nId=intval(Q::G('id'));
		
		$oJiajuevent=JiajueventModel::F('jiajuevent_id=?',$nId)->getOne();
		$oJiajuevent->updateData($GLOBALS['_company_']);
		if($oJiajuevent->isError()){
			$this->E($oJiajuevent->getErrorMessage());
		}

		$this->S('活动更新成功');
	}

}
